package com.eye.web.controller.manage;

import com.eye.system.domain.Task;
import com.eye.system.search.TaskSearch;
import com.eye.system.service.TaskService;
import com.eye.system.util.PageResult;
import com.eye.system.util.Results;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/task/")
@Api(tags = "任务")
public class TaskController {
    @Autowired
    private TaskService taskService;

    @PostMapping("add")
    @ApiOperation("新增任务 ")
    public Results addTask(@RequestBody Task task) {
        Integer addTask = taskService.addTask(task);
        return Results.ok(addTask);
    }

    @PostMapping("select/paging")
    @ApiOperation("分页条件查询任务")
    public Results selectPaging(@RequestBody TaskSearch taskSearch) {
        PageResult pageResult = taskService.selectPaging(taskSearch);
        return Results.ok(pageResult);
    }

    @PostMapping("delete")
    @ApiOperation("根据ID删除任务")
    public Results deleteTask(@RequestParam Integer id) {
        Integer deleteTask = taskService.deleteTask(id);
        return Results.ok(deleteTask);
    }

    @GetMapping("select")
    @ApiOperation("根据ID查询任务")
    public Results selectById(@RequestParam Integer id) {
        Task task = taskService.selectById(id);
        return Results.ok(task);
    }

    @PostMapping("update")
    @ApiOperation("根据ID修改任务")
    public Results updateById(@RequestParam Integer id, @RequestBody Task task) {
        Integer updateTask = taskService.updateTask(id, task);
        return Results.ok(updateTask);
    }
}
